﻿@using DirectSell.Model.Money
@using Webdiyer.WebControls.Mvc;
@model  PagedList<RealMoney>
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/User/Views/Shared/UserLayout.cshtml";
}

<!-- APP MAIN ==========-->
<!-- APP MAIN ==========-->
<main id="app-main" class="app-main">

    <div class="widget">
        <header class="widget-header title2">
            <h4 class="widget-title">申请提现</h4>
        </header><!-- .widget-header -->
        <hr class="widget-separator">
        <form id="form1" class="form-horizontal">
            <div class="widget-body">
                <div class="col-sm-12">
                    <div class="col-sm-4 col-lg-offset-2 bor-1">
                        <div class="widget-body clearfix">
                            <div class="pull-left">
                                <h3 class="widget-title text-success m-b-xl"><span class="counter fs3" data-plugin="counterUp" id="balance">@ViewBag.balance</span>元</h3>
                            </div>
                            <span class="pull-right big-icon watermark fs2"><i class="fa fa-gift"></i></span>
                        </div>
                        <footer class="widget-footer bg-info ">现金钱包</footer>
                    </div>
                </div>
                <div class="form-group">
                    <label for="#" class="col-sm-2 control-label">申请金额</label>
                    <div class="col-sm-5">
                        <input class="form-control" type="text"  required  title="只能填写数字或小数"   name="Amount" id="Amount" placeholder="申请金额"><p style="color:brown">手续费  @ViewBag.Charge%</p> 
                    </div>
                </div><!-- .form-group -->
                <div class="form-group">
                    <label for="#" class="col-sm-2 control-label">实际到账</label>
                    <div class="col-sm-5">
                        <input class="form-control" type="text" readonly="readonly" name="RealAmount" id="RealAmount" placeholder="实际到账">
                    </div>

                </div><!-- .form-group -->
                <div class="form-group">
                    <label for="#" class="col-sm-2 control-label">备注</label>
                    <div class="col-sm-5">
                        <input class="form-control" type="text" name="Remark" placeholder="备注">
                    </div>

                </div><!-- .form-group -->
                <div class="form-group">
                    <label for="#" class="col-sm-2 control-label">二级密码</label>
                    <div class="col-sm-5">
                        <input class="form-control" name="SecondPassWord" required type="password" placeholder="请输入二级密码">
                    </div>
                    <div class="col-sm-1 text-danger f-s"><span class="fa fa-asterisk"></span></div>
                </div><!-- .form-group -->

                <div class="form-group">
                    <label for="#" class="col-sm-2 control-label">验证码</label>
                    <div class="col-sm-4">
                        <input class="form-control" name="CheckCode" type="text" required placeholder="请输入验证码">
                    </div>
                    <div class="col-sm-1"><img id="code" src="/User/VirtualMoney/GetImageValiDateCode" style="width:60px;height:40px;"></div>
                </div><!-- .form-group -->



                <div class="form-group">
                    <div class="col-sm-8 text-center">
                        <button type="submit" class="btn btn-info">确认申请</button>
                    </div>
                </div>

            </div><!-- .widget-body -->
        </form>
    </div><!-- .widget -->

    <div class="widget">
        <section class="app-content">
            <div class="widget-body">
                <h4 class="m-b-lg">申请提现记录</h4>
                    <div class="table-responsive">
                        <div class="text-center p-t-sm p-b-sm">
                            <nav class="page-redcolor">
                                <div id="orders">
                                    <div id="dvCategoryResults">
                                        @Html.Partial("List", Model)
                                    </div>
                                    <div style="width:100%;overflow:auto;">
                                        <div style="float:right">Go to page<select id="pib"></select></div>
                                        @Ajax.Pager(Model, new PagerOptions
                                   {
                                       PageIndexParameterName = "page",
                                       ContainerTagName = "ul",
                                       CssClass = "pagination",
                                       PageIndexBoxId = "pib",
                                       Id = "mypager",
                                       CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>",
                                       DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
                                       PagerItemTemplate = "<li>{0}</li>"
                                   }).AjaxOptions(a => a.SetUpdateTargetId("orders").EnablePartialLoading())
                                    </div>
                                </div>
                            </nav>
                            @section scripts{ @{Html.RegisterMvcPagerScriptResource();}}
                        </div>
                    </div>
                </div>

                                    <!-- .widget -->
        </section><!-- #dash-content -->
    </div><!-- .wrap -->
    <!-- APP FOOTER -->
    <div class="wrap p-t-0">
        <footer class="app-footer">
            <div class="clearfix">
                <div class="copyright text-center w100">@DirectSell.Common.Url.CommonConfig.companyName &copy;</div>
            </div>
        </footer>
    </div>
    <!-- /#app-footer -->
</main>

<!--========== END app main -->
<script type="text/javascript">

    $(function () {
        queryBalance();
    })

    function queryBalance() {
        $.ajax({
            type: "post",
            url: "/User/RealMoney/QueryBalance",
        }).success(function (message) {
            $('#balance').html(message);
        })
    }

    //计算实际到账金额
    $("#Amount").keyup(function () {
        var money = $("#Amount").val();
        $.ajax({
            type: "post",
            url: "/User/RealMoney/QueryCharge",
            data: { money: money },
        }).success(function (message) {
            $('#RealAmount').val(message);
        }).fail(function (err) {
            $("#Amount").val("");
            layer.msg('只能输入数字或小数', { icon: 2 });
        })
    });  



    $('#form1').on('submit', function () {
        layer.confirm('确定要申请提现'+ $('#Amount').val()+ '元？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            formPost();
        }, function () {
            layer.close();
        });
        event.preventDefault() //阻止form表单默认提交
    })
    function formPost() {
        //加载层
        var index = layer.load(1, {
            shade: [0.1, '#fff']
        });
        $.ajax({
            type: "post",
            url: "/User/RealMoney/Apply",
            data: $('#form1').serialize(),
        }).success(function (message) {
            if (message != '成功') {
                layer.msg(message, { icon: 2 });
            }
            else {
                layer.msg('申请提现成功', { icon: 1 });
                queryBalance();
            }
        }).fail(function (err) {
            layer.msg('系统错误,请稍后重试', { icon: 2 });
        })
        layer.close(index)//关闭加载层
    }

    //点击验证码图片，更换验证码
    $("#code").click(function () {
        $(this).attr("src", "/User/RealMoney/GetImageValiDateCode?time=" + (new Date()).getTime())
    });
</script>


